{extend name="base" /}
{block name="body_class"}class="chapter-skin0"{/block}
{block name="chapter_header"}chapter-header{/block}
{block name="header"}
    <meta http-equiv="mobile-agent" content="format=html5; url={:url("/chapter/" . $chapter['article_id'] . "/" . $chapter['id'],"","html","m")}" />
    <meta http-equiv="mobile-agent" content="format=xhtml; url={:url("/chapter/" . $chapter['article_id'] . "/" . $chapter['id'],"","html","m")}" />
{/block}

{block name="body"}
<!--container-->
<div class="chapter-container w960">
    <div class="chapter-bread">
        <span>您的位置 : </span>
        <a href="{$site_config.site_domain}">{$site_config.site_name}</a> &gt;
        <a href="{:url('/book/' .$article['id'],'html',true)}">{$article.title}</a> &gt;
        <a href="{:url('/chapter/' . $article['id'] . '/' . $chapter['id'],'html',true)}">{$chapter.title}</a>
        <div class="source-list">
            <div class="select">
                <p data-value="{$chapter.flag}">{$chapter.source_name}</p>
                <ul>
                    {foreach $chapter.source_list as $item}
                    <li data-flag="{$item.flag | base64_encode}" data-id="{$item.id}" data-value="{$item.site_name}" data-name="{$item.site_name}"  {eq name="$chapter.flag" value="$item.flag"} class="Selected" {/eq}>{$item.site_name}</li>
                    {/foreach}
                </ul>
            </div>
        </div>
    </div>
    <div class="chapter-wrap font-family-01" style="font-size:18px">
        <!--main-->
        <div class="main">
            <div class="title">
                <h1>{$chapter.title}</h1>
                <p>
                    <span>书名：{$article.title}</span>
                    <span>作者：{$article.author}</span>
                    <span class="source_name">来源：{$chapter.source_name}</span>
                    <span>类别：{$article.cid | show_cid_name }</span>
                </p>
            </div>
            <div class="content">
                <?php if($chapter['content'] != "empty") {echo $chapter['content'];}?>
            </div>
            <div class="clearfix"></div>
            <?php echo $showPage;?>
        </div>
        <div class="porn">
            {neq name="$prev" value=""}
            <a href="{:url('/chapter/' . $article['id'] . '/' . $prev['id'],'html',true)}" target="_top" class="prev" >上一章</a>
            {else/}
            <a href="javascript:void (0)" class="prev"> 暂无上一章</a>
            {/neq}

            <a class="index" href="javascript:">目录</a>
            {neq name="$next" value=""}
            <a href="{:url('/chapter/' . $article['id'] . '/' . $next['id'],'html',true)}" target="_top" class="next">下一章</a>
            {else/}
            <a href="javascript:void (0)" class="next">暂无下一章</a>
            {/neq}
        </div>
        <!--main-->
    </div>
    <!--tool-bar-->
    <div class="left-bar">
        <ol class="left-btns">
            <li class="btn-chapter"><a href="javascript:void(0);">目录</a></li>
            <li class="btn-set"><a href="javascript:void(0);">设置</a></li>
            <li class="btn-mobile"><a href="javascript:void(0);">手机</a></li>
            <li class="btn-favorite"><a href="javascript:void(0);">收藏</a></li>
        </ol>
        <div class="show-panel chapter-panel">
            <h3>目录</h3>
            <div class="chapter-box">
                <ul class="clearfix">
                    {foreach $article.chapter_list as $chapter_item}
                    <li {eq name="$chapter.id" value="$chapter_item.id"}class="hover"{/eq} ><a target="_self" href="{:url("/chapter/" . $chapter_item['article_id'] . "/" . $chapter_item['id'],"","html",true)}" title="{$chapter_item.title}">{$chapter_item.title}</a></li>
                    {/foreach}
                </ul>
            </div>
            <a class="hide-panel">关闭</a>
        </div>
        <div class="show-panel set-panel">
            <h3>设置</h3>
            <div class="set-box">
                <dl class="set-skin clearfix">
                    <dt>阅读主题</dt>
                    <dd>
                        <span title="默认" class="skin-0 cur" data-value="0"><i></i></span>
                        <span title="灰色" class="skin-1" data-value="1"><i></i></span>
                        <span title="夜间" class="skin-2" data-value="2"><i></i></span>
                    </dd>
                </dl>
                <dl class="set-font-family clearfix">
                    <dt>正文字体</dt>
                    <dd>
                        <span class="cur" data-value="0">雅黑</span>
                        <span class="" data-value="1">宋体</span>
                        <span class="" data-value="2">楷书</span>
                    </dd>
                </dl>
                <dl class="set-font-size clearfix">
                    <dt>字体大小</dt>
                    <dd>
                        <cite>
                            <span class="prev">A-</span>
                            <span class="size">18</span>
                            <span class="next">A+</span>
                        </cite>
                    </dd>
                </dl>
                <dl class="set-width clearfix">
                    <dt>页面宽度</dt>
                    <dd>
                        <cite>
                            <span class="prev">W-</span>
                            <span class="size">960</span>
                            <span class="next">W+</span>
                        </cite>
                    </dd>
                </dl>
                <p class="set-btns clearfix">
                    <a class="btn-save" href="#">保存</a>
                    <a class="btn-cancel" href="#">取消</a>
                </p>
            </div>
            <a class="hide-panel">关闭</a>
        </div>
        <div class="show-panel mobile-panel">
            <h3>手机阅读</h3>
            <div class="mobile-box">
                <span id="j-qrcode"></span>
                <p style="margin-top: 50px">扫描二维码，随时随地掌上阅读</p>
            </div>
            <a class="hide-panel">关闭</a>
        </div>
    </div>
    <div class="right-bar">
        <ol>
            <li class="btn-gotop"><a href="javascript:void(0);">顶部</a></li>
        </ol>
    </div>
    <!--/tool-bar-->
</div>
<!--/container-->
{/block}
{block name="footer"}
<script type="text/javascript" src="__JS__/qrcode.js"></script>
<script type="text/javascript" src="__JS__/layer/layer.js"></script>
<script type="text/javascript">

    $(function(){
        chapterInit();

        function get_chapter_content(article_id,chapter_id,flag) {

            var layer1 = layer.load();
            $.ajax({
                type: "get",
                data:{
                    article_id:article_id,
                    chapter_id:chapter_id,
                    flag:flag,
                },
                cache:false,
                dataType:"json",
                url: '{:url("/ajax/chapter_content","","html",true)}',
                success: function(info) {
                    if (info.code == 0 && info.data != "") {
                        $(".content").html(info.data);
                        layer.close(layer1);
                    }
                }
            });
        }

        if ("{$chapter.content | strlen}" < 10) {
            $(".content").html("<div class='chapter_content_empty'>章节加载失败请点击右上角更换源阅读!</div>");
            setTimeout(function () {
                get_chapter_content("{$article.id}","{$chapter.id}","{$chapter.flag | base64_encode}");
            },500);
        }

        //生成当前URL二维码
        var url = "{:url('/chapter/' . $article['id'] . '/' . $chapter['id'],'html',true)}";
        $("#j-qrcode").qrcode({width:250,height:250,text:url});

        $(".source-list .select p").click(function(e){
            $(".source-list .select").toggleClass('open');
            e.stopPropagation();
        });

        $(".source-list .select ul li").click(function(e){
            var _this=$(this);
            $(".source-list .select > p").text(_this.attr('data-value'));
            _this.addClass("Selected").siblings().removeClass("Selected");
            $(".source-list .select").removeClass("open");
            e.stopPropagation();

            $(".source_name").html("来源：" + _this.data('name'));
            get_chapter_content("{$article.id}",_this.data('id'),_this.data('flag'));
        });

        $(document).on('click',function(){
            $(".source-list .select").removeClass("open");
        })
    });

</script>
{/block}